/*
 * @Author: 舒克
 * @Official Accounts: 氧化1028
 * @email: 143587623@qq.com
 * @github: https://gitee.com/KingSio
 * @Date: 2020-11-27 19:02:30
 * @LastEditTime: 2021-03-26 16:41:51
 * @FilePath: \哇麦游戏后台\vue\1.vue全站管理系统\vue_shop\src\router\index.js
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
//import Login from "@/components/Login.vue"

//使用路由懒加载,注意：z这里会把三个组件合并在一起了
const Login=()=>import(/*webpackChunkName:"login_home_welcome"*/'@/components/Login.vue')

const Home=()=>import(/*webpackChunkName:"login_home_welcome"*/'@/components/Home.vue')

const Welcome=()=>import(/*webpackChunkName:"login_home_welcome"*/'@/components/Welcome.vue')


//import Home from "@/components/Home.vue"
//import Welcome from "@/components/Welcome.vue"
//import Users from "@/components/user/Users1.vue"
import Users from "@/components/user/Users2.vue"//测试共用组件修改，添加
import Rights from "@/components/power/Rights.vue"//权限列表组件
import Roles from "@/components/power/Roles.vue"//角色权限列表
import Cate from "@/components/goods/Cate.vue"//角色权限列表
import Params from "@/components/goods/Params2.vue"//角色权限列表,2为自己优化的版本
import Goods from "@/components/goods/List.vue"//角色权限列表,2为自己优化的版本
import Add from "@/components/goods/Add.vue"//商品列表-添加商品组件页面
import Order from "@/components/order/Order.vue"//订单管理-订单列表
import Reports from "@/components/reportsed/reports.vue"//订单管理-订单列表

Vue.use(VueRouter)



const router= new VueRouter({
  routes:[
    {
      path: '/',
      redirect:'/login'//重定向到登录页
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
     
      path: '/home',
      component: Home,
      redirect:"/welcome",//重定向到欢迎组件
      children:[
        {path:"/welcome",component:Welcome ,name:"首页",},
        //这里是后端传过来的，所以必须按照规范定义
        { path:"/users",component:Users,name:"用户管理"},

        //权限列表
        {path:"/rights",component:Rights,name:"权限管理"},

        //角色权限列表
        {path:"/roles",component:Roles,name:"角色列表"},

        //商品分类Cate
        {path:"/categories",component:Cate,name:"商品分类"},

        //商品分类参数
        {path:"/params",component:Params,name:"分类参数"},
        
        //商品列表
        {path:"/goods",component:Goods,name:"商品列表"},
        {path:"/goods/add",component:Add,name:"添加商品"},

        //订单管理
        
        {path:"/orders",component:Order,name:"订单列表"},

        //数据统计Reports
        {path:"/reports",component:Reports,name:"数据统计"}
      ]
    },
  
  ]
})
//挂载路由导航守卫
router.beforeEach((to,from,next)=>{
  //to将要访问的路径
  //from代表从哪里来
  //next下一个
  
  //如果默认去登录，就直接让用户跳转登录页面
  if(to.path==="/login") return next()
 
 //获取tonke
 const tokenStr= window.sessionStorage.getItem("token")
  if(!tokenStr){
    return next("/login")
  }
  next()
})
export default router
